package pattern5.ProducerConsumer.demo1.client;

import com.alibaba.fastjson.JSON;
import pattern5.ProducerConsumer.demo1.msgServer.Consumer;
import pattern5.ProducerConsumer.demo1.msgServer.Msg;
import pattern5.ProducerConsumer.demo1.msgServer.MsgManager;
import utils.PrintUtil;

/**
 * @创建人 liweijia
 * @创建时间 2022/7/30
 * @描述 业务消费者只用关心具体的逻辑
 */
public class MyConsumer extends Consumer {

    MyConsumer(MsgManager msgManager) {
        super(msgManager);
    }

    @Override
    protected void consumerTask(Msg msg) {
        PrintUtil.print(String.format("\t\t\t\t\t\t消费者收到消息[%s]", JSON.toJSONString(msg.getMsg())));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        PrintUtil.print(String.format("\t\t\t\t\t\t消费者处理消息完毕[%s]", JSON.toJSONString(msg.getMsg())));
    }
}
